package com.smartscreen.lifeserviceinfomanage.service.impl;

import com.smartscreen.lifeserviceinfomanage.dto.LibraryStatusDTO;
import com.smartscreen.lifeserviceinfomanage.entity.LibraryStatus;
import com.smartscreen.lifeserviceinfomanage.mapper.LibraryStatusMapper;
import com.smartscreen.lifeserviceinfomanage.service.LibraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LibraryServiceImpl implements LibraryService {
    
    @Autowired
    private LibraryStatusMapper libraryStatusMapper;
    
    @Override
    public LibraryStatusDTO getLibraryStatus() {
        List<LibraryStatus> statusList = libraryStatusMapper.selectList(null);
        if (statusList.isEmpty()) {
            return null;
        }
        
        LibraryStatus status = statusList.get(0); // 假设只有一条记录
        return convertToDTO(status);
    }
    
    private LibraryStatusDTO convertToDTO(LibraryStatus status) {
        LibraryStatusDTO dto = new LibraryStatusDTO();
        dto.setIsOpen(status.getIsOpen());
        dto.setOpenHours(status.getOpenHours());
        
        LibraryStatusDTO.SeatingDTO seating = new LibraryStatusDTO.SeatingDTO();
        seating.setTotal(status.getTotalSeats());
        seating.setOccupied(status.getOccupiedSeats());
        seating.setAvailable(status.getAvailableSeats());
        dto.setSeating(seating);
        
        return dto;
    }
}